<?php

namespace App\Http\Controllers\Backstage\User;

use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Http\Request;
//用户模块
class UserController extends Controller
{
    //获取用户列表
    public function getUserList(Request $request)
    {
        $token = $request->query('token');
        //验证权限
        $verifytoken = verifyBackstageToken($token);
        if (is_array($verifytoken)) {
            return $verifytoken;
        }
        //翻页
        $pagenNum = (int)$request->query('page');
        $pageSize = (int)$request->query('pageSize');
        if ($pageSize > 50) {
            return false;
        }
        $page = $pagenNum - 1;
        if ($page != 0) {
            $page = $pageSize * $page;
        }
        $count = User::count();
        $info =  User::offset($page)
            ->limit($pageSize)
            ->orderByDesc("create_time")
            ->get();
        if ($info) {
            $info = json_decode($info, true);
            foreach ($info as $key => $value) {
                $info[$key]['nickName'] = urldecode($value['nickName']);
                $info[$key]['create_time'] = date("Y-m-d", $value['create_time']);
            }
            $data = success();
            $data['data'] = $info;
        } else {
            $data = fail();
        }
        $data['count'] = $count;
        return $data;
    }
}
